import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
def f(r, t):
x, y, z=r[0], r[1], r[2]
sigma=10.
rho=28.
beta=8/3
fx=sigma*(y-x)
fy=x*(rho-z)-y
fz=x*y-beta*z
return np.array([fx, fy, fz])
if __name__=="__main__":
t=np.linspace(0, 50, 10000)
dim=3
r=np.ones([len(t), dim])
k=np.zeros([4, dim], float)
h=t[1]-t[0]
for i in range(1, len(t)):
k[0]=h*f(r[i-1], t[i-1])
k[1]=h*f(r[i-1]+k[0]/2, t[i-1]+h/2)
k[2]=h*f(r[i-1]+k[1]/2, t[i-1]+h/2)
k[3]=h*f(r[i-1]+k[2], t[i-1]+h)
r[i]=r[i-1]+(k[0]+2*k[1]+2*k[2]+k[3])/6
fig=plt.figure()
ax=fig.gca(projection="3d")
ax.plot(r[:, 0], r[:, 1], r[:, 2] )
plt.show()